#define  _CRT_SECURE_NO_WARNINGS
#include <stack>
#include <string>
#include <vector>
#include <functional>
#include <unordered_map>
using namespace std;

class Solution {
public:
    void func(stack<int>& st, string& oper)
    {
        int right = st.top();
        st.pop();
        int left = st.top();
        st.pop();
        if (oper == "+") st.push(left + right);
        else if (oper == "-") st.push(left - right);
        else if (oper == "*") st.push(left * right);
        else if (oper == "/") st.push(left / right);
    }
    int evalRPN(vector<string>& tokens) {
        stack<int> st;
        for (auto& str : tokens)
        {
            if (str == "+" || str == "-" || str == "*" || str == "/")
                func(st, str);
            else
                st.push(stoi(str));
        }
        return st.top();
    }
};

class Solution {
public:
    Solution()
    {
        funcmap = {
            { "+", [](int left, int right) {return left + right; } },
            { "-", [](int left, int right) {return left - right; } },
            { "*", [](int left, int right) {return left * right; } },
            { "/", [](int left, int right) {return left / right; } },
        };
    }
    int evalRPN(vector<string>& tokens) {
        stack<int> st;
        for (auto& str : tokens)
        {
            if (funcmap.count(str))
            {
                int right = st.top();
                st.pop();
                int left = st.top();
                st.pop();
                st.push(funcmap[str](left, right));
            }
            else
                st.push(stoi(str));
        }
        return st.top();
    }
    unordered_map<string, function<int(int, int)>> funcmap;
};